﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business;
using DataAccess;

namespace BaseWeb.GridView.TGridView.Modules
{
    public partial class TGridViewModule : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDropList();
                BindGrid();
            }
        }

        /// <summary>
        /// 绑定表名列表
        /// </summary>
        private void BindDropList()
        {
            this.ddlTabaleName.Items.Clear();
            this.ddlTabaleName.Items.Add(new ListItem() { Text = "li_Class", Value = "li_Class", Selected = true });
            this.ddlTabaleName.Items.Add(new ListItem() { Text = "li_Student", Value = "li_Student" });
        }


        /// <summary>
        /// 绑定Gridview
        /// </summary> 
        private void BindGrid()
        {
            li_Student st = new li_Student();
            if (!string.IsNullOrEmpty(this.ddlTabaleName.SelectedValue))
            {
                switch (this.ddlTabaleName.SelectedValue)
                {
                    case "li_Class":
                        {
                            var list = CommonSystem.Instance.Service.GetAllList<li_Class>();
                            this.GridView1.DataSource = list;
                            break;
                        }
                    case "li_Student":
                        {
                            var list = CommonSystem.Instance.Service.GetAllList<li_Student>();
                            this.GridView1.DataSource = list;
                            break;
                        }
                }
                //var list = CommonSystem.Instance.Service.GetAllList<T>();
                this.GridView1.DataBind();
            }
        }

        protected void ddlTabaleName_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindGrid();
        }


    }
}